<template>
  <div class="home_message">
    <div class="jiance"><span>当前城市所有检测站</span><span>更新时间 {{ datas[0] }}&nbsp;&nbsp;{{ datas[1] }}</span></div>
    <div class="fengchang">风场地图<van-icon name="flag-o" /></div>
    <div class="yuanquan">
      <div class="wendu">{{ cityList.aqi }}</div>
      <div>
        <div  @click="chuxian">  <van-icon name="smile-o" />{{ cityList.quality }}<van-icon name="arrow" /></div>
      
        <div>
          <div :class="falg?'tishi1':'chuxian'">
            <span class="pm">pm2.5:{{ cityList.pm25 }}</span><span class="pm">pm10:{{ cityList.pm10 }}</span><span class="pm">so2:{{ cityList.so2 }}</span
            ><span class="pm">no2:{{ cityList.no2 }}</span><span class="pm">o3:{{ cityList.o3 }}</span><span class="pm">co:{{ cityList.co }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="chuxing">
      <div class="tishi" @click="tishi"><van-icon name="bulb-o" />出行提示</div>
      <div class="aaa">
        <span>{{tempList.text}}{{ tempList.code }}</span><span><van-icon name="guide-o" />{{tempList.wind_speed}}级</span
        ><span><van-icon name="flower-o" />{{tempList.humidity}}%</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { homeAir,homeTemp } from '../../service/cityService'
import { useRouter } from 'vue-router';

let router=useRouter();
let cityList: any = ref([])
let tempList:any=ref([])
let name = ref('')
let falg=ref(true);
let date=ref("")
let datas:any=ref([]);
let aa = localStorage.getItem('city')
if (aa?.length) {
  name.value = JSON.parse(aa).name
}

const tishi=()=>{
  router.push("/tishi")
}

const cityAir = async () => {
  let { data } = await homeAir({
    key: 'S_kv1Ro8FrmQ4UeD9',
    location: name.value,
    language: 'zh-Hans',
    scope: 'city'
  })
  cityList.value = data.results[0].air.city
  date.value=cityList.value.last_update;
  datas.value=date.value.slice(0,19).split("T");
}
const cityTemp=async()=>{
  let {data}=await homeTemp({
    key: 'S_kv1Ro8FrmQ4UeD9',
    location: name.value,
    language: 'zh-Hans',
    unit:"c"
  })
  tempList.value=data.results[0].now
}

const chuxian=()=>{
  falg.value=!falg.value;
}

onMounted(() => {
  cityAir()
  cityTemp()
})
</script>

<style scoped lang="scss">
.home_message {
  padding: 10px;
  position: relative;
.aaa{
  span{
    margin: 0 5px;
  }
}
  .fengchang {
    padding: 5px;
    border-radius: 0 20px 20px 0;
    position: absolute;
    top: 49px;
    left: 0;
    color: #fff;
    background: rgba($color: #fff, $alpha: 0.4);
  }
}
.yuanquan {
  border: 5px solid rgba($color: #fff, $alpha: 0.5);
  color: #fff;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin-left: 35%;
  margin-top: 10%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex-direction: column;
  position: relative;
  .tishi1 {
    display: none;
  }
  .chuxian{
    display: block;
    width: 200px;
    height: 100px;
    background: rgba($color: #fff, $alpha: 0.9);
    color: #000;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    position: absolute;
    top: 15px;
    left: -60px;
    z-index: 100;
    span{
    width: 30%;
    display: block;
  }
  }
  .wendu {
    font-size: 36px;
    color: #fff;
  }
}
.chuxing {
  text-align: center;
  margin-top: 20px;
  color: #fff;
  font-size: 12px;
  line-height: 30px;
  .tishi {
    background: rgba($color: #fff, $alpha: 0.3);
    width: 80px;
    border-radius: 20px;
    margin-left: 37%;
  }

}
.jiance {
  font-size: 12px;
  display: flex;
  justify-content: space-between;
}
</style>
